<template>
	<div>
		<el-select-v2
			v-model="levelId"
			:options="options"
			:props="{
				label: 'name',
				value: 'id'
			}"
			@change="changeLevel"></el-select-v2>
		<el-divider />
		<component :customerId="props.customerId" ref="wyObject" :is="Form" :formData="wyform" :rules="rules" :save="save"></component>
	</div>
	
</template>

<script setup>
import { reactive, ref } from 'vue'
import { post, get } from '@/axios'
import { ElMessage } from 'element-plus'
import { dayjs } from 'element-plus'
import Form from './components/form'
const props = defineProps(['customerId', 'urls'])
const emits = defineEmits(['update:show'])
const wyObject = ref()
const wyform = ref([])
const levelId = ref(null)
const options = ref(await getLevel())

function getLevel() {
	return new Promise(resolve => {
		get('/nurselevel/list', { status: 1 }, content => {
			resolve(content)
		})
	})
}
const rules = {}

function save() {
	const form = []
	for (const i in wyform.value) {
		const json = {}
		json.itemId = wyform.value[i].id
		json.custormerId = props.customerId
		json.levelId = levelId.value
		json.nurseNumber = wyform.value[i].nurseNumber
		json.buyTime = wyform.value[i].buyTime
		json.maturityTime = wyform.value[i].maturityTime
		form.push(json)
	}
	post(props.urls.add, { content: JSON.stringify(form) }, content => {
		// emits('update:show', false)
	}, wyObject.value.formObj)
	console.dir(wyform)
}
function changeLevel () {
	get('/nurselevelitem/getItem', { levelId: levelId.value }, content => {
		for (const i in content) {
			content[i].buyTime =dayjs(new Date()).format('YYYY-MM-DD')
			content[i].nurseNumber = 0
			content[i].maturityTime = ''
		}
		wyform.value = content
	})
}
</script>

<style scoped lang="scss">
.el-select {
	width: 250px;
}
</style>